package org.yu.register.world;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

//咕咕咕咕咕？？？？？？？咕！！！
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
@SuppressWarnings("unused")
public class ChaosBiomeSource extends BiomeSource {
    public static final Codec<ChaosBiomeSource> CODEC=RecordCodecBuilder.create(instance->
            instance.group(
                    Codec.list(SourcePresent.CODEC)
                            .fieldOf("biomes")
                            .forGetter(ChaosBiomeSource::getSourcePresents))
                    .apply(instance,ChaosBiomeSource::new)
    );
    protected final List<SourcePresent> sourcePresents;
    protected ChaosBiomeSource(List<SourcePresent> pPossibleBiomes) {
        super(pPossibleBiomes.stream().map(SourcePresent::biomeHolder));
        this.sourcePresents=pPossibleBiomes;
    }

    public List<SourcePresent> getSourcePresents() {
        return sourcePresents;
    }

    @Override
    protected Codec<? extends BiomeSource> codec() {
        return CODEC;
    }

    @Override
    public BiomeSource withSeed(long pSeed) {
        return this;
    }

    @Override
    public Holder<Biome> getNoiseBiome(int p_204238_, int p_204239_, int p_204240_, Climate.Sampler p_204241_) {
        return getSourcePresents().get(0).biomeHolder;
    }
    protected static record SourcePresent(float altitude,float chaos,float darkness,Holder<Biome> biomeHolder){
        public static final Codec<SourcePresent> CODEC= RecordCodecBuilder.create(
                instance -> instance.group(
                        Codec.FLOAT.fieldOf("altitude").forGetter(SourcePresent::altitude)
                        ,Codec.FLOAT.fieldOf("chaos").forGetter(SourcePresent::chaos)
                                ,Codec.FLOAT.fieldOf("darkness").forGetter(SourcePresent::darkness)
                        ,Biome.CODEC.fieldOf("biome").forGetter(SourcePresent::biomeHolder)
                ).apply(instance,SourcePresent::new)
        );
    }
}
